package day16;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author tongchen
 * @create 2023-03-22 20:12
 */
public class Main1 {
    public static void main(String[] args) {
        //输入测试用例
        Scanner scanner=new Scanner(System.in);
        String s=scanner.nextLine();
        //分牌
        String[] split = s.split("-");
        String self=split[0];
        String other=split[1];
        //继续分牌
        String[] selfO = self.split(" ");
        String[] otherO = other.split(" ");
        //比较个数
        if(selfO.length!= otherO.length){
            if(selfO.length==2||otherO.length==2){
                if (selfO[0].equals("joker")||otherO[0].equals("joker")){
                    System.out.println("joker JOKER");
                    return;
                }
            }
            if(selfO.length==4){
                System.out.println(self);
                return;
            }
            if(otherO.length==4){
                System.out.println(other);
                return;
            }
            System.out.println("ERROR");
            return;
        }else{
            if(selfO[0].equals("joker")||otherO[0].equals("joker")){
                System.out.println("joker JOKER");
                return;
            }
            //创建哈希表
            int count=0;
            HashMap<String, Integer> map = new HashMap<>();
            map.put("3", count++);
            map.put("4", count++);
            map.put("5", count++);
            map.put("6", count++);
            map.put("7", count++);
            map.put("8", count++);
            map.put("9", count++);
            map.put("10", count++);
            map.put("J", count++);
            map.put("Q", count++);
            map.put("K", count++);
            map.put("A", count++);
            map.put("2", count++);
            if(map.get(selfO[0])>map.get(otherO[0])){
                System.out.println(self);
            }
            else{
                System.out.println(other);
            }

        }

    }
}
